import java.awt.Point;
import java.util.ArrayList;


public class Reverse {
	private static final int BLACK = 0;
	private static final int WHITE = 1;
	private int target;
	
	private ArrayList<Point> list;
	private ArrayList<Point> reverse;
	private Board board;
	private Point newPlaced;

	public Reverse(){
		list = new ArrayList<Point>();
		reverse = new ArrayList<Point>();
		board = new Board();
	}
	public void calc(Board b, int t, Point p){
		board = b;
		target = t;
		list.clear();
		reverse.clear();
		newPlaced = p;
		search8(newPlaced);
	}
	
	public ArrayList<Point> getReverse(){
		return reverse;
	}
	private void search8(Point p){
		search(p,new Point(p.x,p.y-1));
		search(p,new Point(p.x-1,p.y-1));
		search(p,new Point(p.x-1,p.y));
		search(p,new Point(p.x-1,p.y+1));
		search(p,new Point(p.x,p.y+1));
		search(p,new Point(p.x+1,p.y+1));
		search(p,new Point(p.x+1,p.y));
		search(p,new Point(p.x+1,p.y-1));
	}
	private void search(Point original, Point p){
		if(board.checkBlock(p)!=-1&&board.checkBlock(p)!=target){
			if(!list.contains(p)&&p.x>=1&&p.x<=8&&p.y>=1&&p.y<=8)
				list.add(p);
			search(p,new Point(p.x+(p.x-original.x),p.y+(p.y-original.y)));
		}
		else if(board.checkBlock(p)==target){
			reverse.addAll(list);
			list.clear();
		}
		else
			list.clear();
	}		
}
